<!DOCTYPE html>
<html>
<head>
    <title>add</title>
    <include file='public/head'>
    <style>
        .layui-legend-size{font-size:14px !important;}
        .layui-nopadding{padding:0 !important;}
        .layui-overflow{overflow:auto;}
        .layui-nomargin{margin: 0 !important;}
        .layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
        .layui-input{height:30px !important; }
        .layui-form-search-item .layui-inline{margin-bottom: 5px;} 
        .layui-form-search-item label{margin-left: 15px;}
        .layui-table-page {padding: 7px 0px 0px;}
        .layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
    </style>
</head>
<body>
    <div class="layui-tab">
        <!-- 表单开始 -->
        <form class="layui-form" id="f">
            <div class="layui-form-item">
                <label class="layui-form-label">所属分类</label>
                <div class="layui-input-inline">
                    <select name="add[pid]" lay-search="">
                        <option value="">顶层分类</option>
                        <volist name="cats" id="vo"> 
                        <option value="{$vo.catid}" <if condition="$vo['level'] gt 3">disabled="disabled"</if>  ><?php if ($vo['level'] != 0) echo '|'; ?><?php echo str_repeat('-', $vo['level']*7)?>{$vo.catname}</option>
                        </volist>
                    </select>
                </div>
            </div>  
            <div class="layui-form-item">
                <label class="layui-form-label">分类名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="add[catname]" class="layui-input" required lay-verify="catname" placeholder="请输入分类名称" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否显示</label>
                    <input type="checkbox" name="add[isshow]" lay-skin="switch" lay-text="显示|隐藏"  value="1"  checked >
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否推荐</label>
                    <input type="checkbox" name="add[isfloor]" lay-skin="switch" lay-text="是|否" value="1"  >
            </div> 
            <div class="layui-form-item">
                <input type="hidden" class="tupain" name="add[catimg]" value="">
                <label class="layui-form-label">分类图片</label>
                <label>
                <img src="__PLUGIN_TMPL__/public/image/timg.png"  class="logoimg" style="height: 100px;">
                <input type="text" id="front" style="position:absolute;opacity:0;">
                </label>
            </div>
        </form>
        <!-- 表单结束 -->
    </div>
<include file='public/scripts'>
<script type="text/javascript">
    var tijiao = function(){
        if($("input[name='catname']").val() == ''){
            layer.msg('请输入分类名');
            return false;
        }
        var dara = $("#f").serialize();
        $.ajax({
            url:"{:cmf_plugin_url('Goods://goods_cats/add')}",
            data:dara,
            type:'post',
            success:function(data){
                if (data.code == 200) {
                    layer.msg(data.message,{icon:1,time:1500},function(){
                        parent.layer.closeAll();
                        parent.location.reload(); 
                    });
                } else {
                    layer.msg(data.message,{icon:2,time:1500});
                }
            },
            error:function()
            {
                layer.msg('系统错误',{icon:2,time:1500});
            }
        })
    }
</script>
<script>    
window.onload=function(){
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#front',
            url:"{:cmf_plugin_url('Goods://goods_cats/upload')}"
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $(".logoimg").attr('src', result);
                });
            }
            ,done: function(res){
                console.log(res);
                if ( res.code != 200 ){
                    return layer.msg(res.message,{icon:2,time:1500});
                }
                $(".tupain").val(res.data);
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
}
</script>
</body>
</html>